package com.weijianhuawen.wjblog.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description: 用于构建api文档，但在本项目中主要用作提升调试效率
 * @date: 2024-10-15 17:35
 */

@Configuration
@EnableSwagger2WebMvc
@Profile("dev") // 只在 dev 环境中开启
public class Knife4jWebConfig {
    @Bean("webApi")
    public Docket createApiDoc() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo())
                //分组名称
                .groupName("web 前台接口")
                .select()
                //指定扫描路径
                .apis(RequestHandlerSelectors.basePackage("com.weijianhuawen.wjblog.web.controller"))
                .paths(PathSelectors.any())
                .build();

        return docket;
    }

    /**
     * 构建api信息
     * @return api信息
     */
    private ApiInfo buildApiInfo() {
        return new ApiInfoBuilder()
                .title("WJBlog 博客平台前台文档接口")
                .description("前后端分离项目")
                .termsOfServiceUrl("weijianhuawen.com")
                .contact(new Contact("未见花闻", "https://weijianhuawen.com", "weijianhuawen@163.com"))
                .version("1.0.0")
                .build();

    }
}
